<?php

class Shops extends Eloquent {
    protected $table = 'shops';
    public static function Insert($name,$address,$phone,$website,$logo_path)
    {
        try
        {
            echo $name;
            $query_insert="INSERT INTO shops (created_at,updated_at,name,address,phone,website,logo)
	                       VALUES ( CURRENT_TIMESTAMP,
	                                 CURRENT_TIMESTAMP,
	                                 '".$name."',
                                     '".$address."',
                                     '".$phone."',
                                     '".$website."',
                                     '".$logo_path."'
                                    )";
            //echo $query_insert;
            DB::insert($query_insert);
            return true;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function ShopNameisExist($name)
    {
        return self::where('name','=',$name)->count()>0;
    }
    public static function shopIdisExist($id)
    {
        return self::where('id','=',$id)->count()>0;
    }
        
//   public fuction GetShopid($shop_id){
//        $id= DB::table('shop')->where("id","=",$shop_id)->get();
//        return $id;
//        
//    }

    
    public static function getShopId($name)
    {
        try
        {
            $query_shop_id=self::where('name','=',$name)
                                ->select('id')->first();

            //var_dump($query_shop_id); exit;
            if($query_shop_id)
            {
                return $query_shop_id->id;
            }
            return -1;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function Edit($name,$address,$phone,$website,$logo_path,$shop_id)
    {
        try{
            $query_update="UPDATE shops 
                           SET updated_at=CURRENT_TIMESTAMP,
                                name ='$name',
                                address='$address',
                                phone='$phone',
                                website='$website',
                                logo='$logo_path'
                                      
                                WHERE id='$shop_id'";
                                        

            //echo $query_update;
            DB::update($query_update);
            return true;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    
}
